﻿CREATE TRIGGER [dbo].[TR_Image_Insert]
	ON [dbo].[Image]
	AFTER INSERT
	AS
	BEGIN
		SET NOCOUNT ON
		-- Check to get the folder privacy when an image is uploaded to the folder
		MERGE [dbo].[Image] AS T
		USING
		(
			SELECT I.[Id], F.[IsPrivate]
			FROM INSERTED I
			INNER JOIN [dbo].[Folder] F ON I.[FolderId] = F.[Id]
		) AS S
		ON T.[Id] = S.[Id] WHEN MATCHED THEN UPDATE SET T.[IsFolderPrivate] = S.[IsPrivate];
	END
